/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedbeans;

import beans.Atualizacao;
import beans.Usuario;
import beans.Video;
import java.util.Calendar;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import persistence.DAO;
import persistence.DAOUsuario;
import persistence.EMF;

/**
 *
 * @author cassiano
 */
@ManagedBean
@RequestScoped
public class VideoMB {

    public VideoMB() {
    
    }
    
    public void saveVideo(){
    
        
        
        FacesContext aFacesContext = FacesContext.getCurrentInstance();
        ServletContext context =
                (ServletContext) aFacesContext.getExternalContext().getContext();
        HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        Usuario u = (Usuario) session.getAttribute("usuarioLogado");
        ///aqui vao os metodos para add videos
        
        DAO dao = new DAO(EMF.getEntityManager(), Usuario.class);
        dao.atualiza(u);
        session.removeAttribute("usuarioLogado");
        session.setAttribute("usuarioLogado", u);
        UsuarioMB umb = new UsuarioMB();
        umb.setUs(u);
        Atualizacao a =new Atualizacao();
        a.setDataAtualiza(Calendar.getInstance().getTime());
        a.setUserPublica(u);
        a.setAlvo("Alterou a foto do perfil");
        a.setIdAlvo(Long.valueOf("2"));
        DAO daoat = new DAO(EMF.getEntityManager(), Usuario.class);
        daoat.salva(a);
        DAOUsuario daou = new DAOUsuario(EMF.getEntityManager());
        daou.atualizacoes(u, a);
    
    }
    
    
}
